Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new author creation error on socials #3578

Merged
merged 5 commits into from
May 9, 2024
Merged

Conversation

mlbrgl
Copy link
Member

@mlbrgl mlbrgl commented May 6, 2024

fixes #3576

Both GdocBase instances and OwidGdocBaseInterface objects implement the same interface. However, GdocBase instances leak methods into loadGdocFromGdocBase, which override subclasses implementations.

With regards to overriding the GdocAuthor subclass with an instance of the parent class, three approaches have been reviewed:

  • (selected) lodash defaults (see description in code)
  • lodash omitBy (see description in code)
  • GdocBase.toJSON: addresses a problem with similar roots

This PR only fixes GdocAuthor, but we should expand this to all Gdoc* subclasses created by the loadGdocFromGdocBase factory function.

Copy link
Member Author

mlbrgl commented May 6, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @mlbrgl and the rest of your teammates on Graphite Graphite

@owidbot
Copy link
Contributor

owidbot commented May 6, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-fix-author-creation

SVG tester: Number of differences (default views): 0

Number of differences (all views): 0

Edited: 2024-05-06 14:05:32 UTC
Execution time: 1.23 seconds

@mlbrgl mlbrgl requested a review from ikesau May 6, 2024 13:08
@mlbrgl mlbrgl marked this pull request as ready for review May 6, 2024 13:08
Copy link
Member Author

mlbrgl commented May 7, 2024

@ikesau if you haven't started reviewing this, let me re-assign to @danyx23, as he ran into a similar issue I believe. I'll assign you the next one.

Copy link
Member

@ikesau ikesau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments are a bit verbose in my humble o, but I can confirm this fixes the issue 🙂

tested by creating and saving an author page on master and this branch, inspected stored JSON in the DB

@ikesau
Copy link
Member

ikesau commented May 8, 2024

If this is causing issues in other places, could you update all the other GdocBase inheritors to use defaults too? 🙂

@danyx23
Copy link
Contributor

danyx23 commented May 9, 2024

I like the verbose comments :) - thanks for fixing this, Matthieu! I agree that it would be nice to do this for all classes already in this PR

@mlbrgl
Copy link
Member Author

mlbrgl commented May 9, 2024

yes, I'm indeed using long comments as a warning and a deterrent: the longer the comment the more I'll think about changing this line in the future 😄

thank you both for the review, I've updated the other classes.

@mlbrgl mlbrgl merged commit c6d2547 into master May 9, 2024
35 checks passed
@mlbrgl mlbrgl deleted the fix-author-creation branch May 9, 2024 14:27
mlbrgl added a commit that referenced this pull request May 17, 2024
… overridden in Object.assign (#3600)

*alternate solution to #3578, which had to be reverted because [this.content in GdocPost](https://github.com/owid/owid-grapher/blob/3691a52abfa41b34d7853df84df3329d80a9a187/db/model/Gdoc/GdocPost.ts#L34-L36) would  be honored by _.defaults as a property not to override, but would result in the `content` property not respecting `OwidGdocContent` at run time.*

### What changed?

This PR promotes GdocBase instance-level functions (e.g. `_enrichSubclassContent` as class methods.

### Why make this change?

GdocAuthor (but also GdocPost, GdocHomepage and Gdoc DataInsight) are created from a GdocBase instance (only when inserting a new Gdoc) using `Object.assign(gdocAuthor, gdocBase)`. This call lists all enumerable properties on GdocBase, including instance-level functions such as `_enrichSubclassContent`, and overrides the subclass version.

This leads to the subclass enrichment not being performed, and in the case of author creation, an error.

## Follow-up

Promoting instance-level functions to class methods on `GdocBase` is enough to solve this issue, but we should consider whether to apply the same treatment to the GdocBase subclasses too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a new author fails on unenriched socials block
4 participants